// 不需要验证的路由

import { BrowserRouter as Router, Route, Switch, Redirect } from 'react-router-dom';
import Page404 from '../pages/errorPage/404';
import App from '../App';
import { IFMenuBase } from './config';
import AllComponents from '../pages/';
import { constantRoutes } from './routes';

const mainRouters = () => {
    const routeItem = (r: IFMenuBase) => {
        const Component = r.component && AllComponents[r.component];
        return (
            <Route
                key={r.route || r.path}
                exact
                path={r.route || r.path}
                render={(props: any) => {
                    return <Component></Component>;
                }}
            />
        );
    };
    return (
    <Router>
        <Switch>
            <Route exact path="/" render={() => <Redirect to="/app/dashboard/index" push />} />
            <Route path="/app" component={App} />
            {constantRoutes.map((item) => routeItem(item))}
            <Route component={Page404} />
        </Switch>
    </Router>
)};

export default mainRouters;
